//
//  PPGroupDetailViewController.m
//  pet
//
//  Created by 陈无忌 on 1/8/15.
//  Copyright (c) 2015 whalefin. All rights reserved.
//

#import "PPGroupDetailViewController.h"
#import "PPSystemConfiguraton.h"
#import "supportingHeadFiles.h"

@interface PPGroupDetailViewController ()
@property (nonatomic, strong) PPSystemConfiguraton *config;

@end

@implementation PPGroupDetailViewController

- (PPSystemConfiguraton *)config
{
    if (!_config) {
        _config = [PPSystemConfiguraton sharedSystemConfiguration];
    }
    return _config;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self fetchGroupInfo];
    // Do any additional setup after loading the view.
}

- (void)fetchGroupInfo
{
    [[EaseMob sharedInstance].chatManager asyncFetchGroupInfo:self.group.easeMobGroupId completion:^(EMGroup *group, EMError *error) {
        if (!error) {
            self.group.group = group;
//            [self viewInit];
        }
        else{
            [PPHUD hudShowWithString:@"群组详情获取失败，请稍后再试" andView:self.view];
        }
    } onQueue:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)joinGroup:(id)sender {
    [[EaseMob sharedInstance].chatManager asyncJoinPublicGroup:self.group.easeMobGroupId completion:^(EMGroup *group, EMError *error) {
        if(!error)
        {
            NSString *url = [PPAPIList getAPIList].PPJoinGroup;
            NSDictionary *params = @{@"easeMobGroupId":self.group.easeMobGroupId,@"userId":@(self.config.userInfo.id)};
            [httpRequst POST:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
                NSNumber *processResult = responseObject[@"processResult"];
                NSString *msg = responseObject[@"errorMsg"];
                [PPHUD hudShowWithString:msg andView:self.view];
            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                [PPHUD hudShowWithString:@"网络不给力" andView:self.view];
            }];
        }
        else{
            [PPHUD hudShowWithString:@"加入群组失败，请重新操作" andView:self.view];
        }
    } onQueue:nil];
    
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
